package com.huwei.boxuegu.fragment;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.huwei.boxuegu.R;
import com.huwei.boxuegu.activity.LoginActivity;

/**
 * Created by Administrator on 2018/4/2.
 */

public class MyFragment extends Fragment {
    //http://1633.applinzi.com/public/?s=App.User.Login&username=1633class&password=123456
    ImageView imageView;
    TextView textView;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, final Bundle savedInstanceState) {
        View view =  inflater.inflate(R.layout.fragment_my,container,false);
        imageView = view.findViewById(R.id.img);
        textView = view.findViewById(R.id.username);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i("MyFragment","login");
                //判断是否已经登陆了
                SharedPreferences sp = getActivity().getSharedPreferences("login", Context.MODE_PRIVATE); //别的进程读不到
               boolean islogin = sp.getBoolean("islogin",false);
                if (islogin){
                    Toast.makeText(getActivity(),"已经登陆过了",Toast.LENGTH_LONG).show();
                    return;
                }
                Intent intent = new Intent(getActivity(), LoginActivity.class);
                startActivity(intent);
            }
        });
        return view;
    }

    @Override
    public void onResume() {
        SharedPreferences sp = getActivity().getSharedPreferences("login", Context.MODE_PRIVATE); //别的进程读不到
        String username = sp.getString("usrname","点击登录");
        textView.setText(username);
        super.onResume();
    }
}
